<?php

namespace Modules\Common\Http\Middleware;

use Catch\Facade\Admin;
use Closure;
use Illuminate\Http\Request;
use Modules\User\Support\AdminBehaviorLogger;
use Pro\Support\Helper;
use Symfony\Component\HttpFoundation\Response;

class AdminBehaviorMiddleware
{
    /**
     * Handle an incoming request.
     *
     * @param  \Closure(\Illuminate\Http\Request): (\Symfony\Component\HttpFoundation\Response)  $next
     */
    public function handle(Request $request, Closure $next): Response
    {
        //执行控制器动作
        $response = $next($request);
        //解析用户行为
        if($behavior = $request->attributes->get('behavior')){
            $action =  $request->route()->getActionName();
            AdminBehaviorLogger::logCreate($action, $behavior);
        }
        return $response;

    }
}
